<template>
  <view class="g-content">
    <uni-card
      class="card-course"
      :is-shadow="true"
      v-for="item in list"
      :title="item['课程名']"
      :extra="item['课时数']+''"  
      :id="item['课程号']"
    >
      <view><span>上课时间：</span>{{ item['上课时间'] }}</view>      
      <view><span>上课地点：</span>{{ item['上课地点'] }}</view>
      <view><span>教授专业：</span>{{ item['教授专业'] }}</view>
      <view><span>实验课节数：</span><uni-easyinput v-model="item['实验课节数']"></uni-easyinput></view>
      <button @click="_addExp(item['课程号'], item['实验课节数'])">新建实验课</button>
    </uni-card>
  </view>
</template>

<script>
  import Teacher from '../../../api/Teacher.js';
  export default {
    data(){
      return{
        uid: this.$store.state.token.id,
        list: []
      }
    },
    onInit() {
      this.uid = this.$store.state.token.id;
    },
    onLoad() {
      this._initList();
    },
    methods:{
      async _initList(){
        const rm = (await Teacher.courses(this.uid));
        this.Test.log('老师-学期课程',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('无课程');
            this.list = [];
            return;
          }
          this.list = rm[1].data;
          //this.Toast.show('数据已加载');
        }
      },
      async _addExp(cid, num){
        uni.showLoading();
        const rm = (await Teacher.setExp(cid, num));
        this.Test.log('老师-添加实验课回执',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            uni.hideLoading();
            this.Toast.show('添加失败');
            return;
          }
          uni.hideLoading();
          this.Toast.show('添加成功');
        }
        uni.hideLoading();
        this.Toast.show('网络错误');
      }
    }
  }
</script>

<style>
</style>
